package com.xunk.scene.service;

import com.xunk.common.core.domain.ControlDeviceParam;
import com.xunk.common.core.web.domain.AjaxResult;
import com.xunk.scene.util.RedisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xunk.equipment.api.RemoteEquipmentService;

import java.util.List;

/**
 * @ProjectName: HIM
 * @Package:  com.xunk.scene.service
 * @ClassName: DeviceService
 * @Author: tangguangyuan
 * @Description: 操作设备
 * @Date: 2021/5/8 13:33
 * @Version: 1.0
 */
@Service
public class DeviceService {
    private static final Logger log = LoggerFactory.getLogger(DeviceService.class);
    @Autowired
    private RemoteEquipmentService remoteEquipmentService;

    @Autowired
    private RedisUtil redisUtil;

    /**
     * 调用设备管理的批量执行设备动作功能
     * @param controlList
     * @return
     */
    public AjaxResult controlDevice(List<ControlDeviceParam> controlList){
        log.info("-------------设备动作执行开始----------");
        log.info(String.format("执行动作%s",controlList.toString()));

        String sceneKey = redisUtil.getKey();

        //feign调用设备管理平台设置设备属性
        AjaxResult result =  remoteEquipmentService.controlDevice(sceneKey,controlList);

        log.info(String.format("设备动作执行%s",result.isSuccess() ? "成功":"失败"));
        log.info("-------------设备动作执行结束----------");
        return result;
    }

}
